/*
 * @Author: your name
 * @Date: 2021-05-19 21:58:55
 * @LastEditTime: 2021-05-19 22:04:56
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \learn_err\src\main.rs
 */
use std::io;
use std::io::Read;
use std::fs::File;

fn main() {
    println!("Hello, world!");

    let r = read_username_from_file();

    match r {
        Ok(file) => println!("file = {}", file),
        Err(error) => println!("err is {}", error),
    };
}

fn read_username_from_file() -> Result<String, io::Error>{
    let f = File::open("hello.txt");
    let mut f = match f {
        Ok(file) => file,
        Err(error) => return Err(error),
    };

    let mut s = String::new();
    match f.read_to_string(&mut s) {
        Ok(_) => Ok(s),
        Err(error) => Err(error),
    }

}